package com.xm.test.easyexport.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xm.component.easyexport.EasyExcel;
import com.xm.test.easyexport.generator.domain.Water;
import com.xm.test.easyexport.generator.mapper.WaterMapper;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class ExportController {


    @Resource
    private WaterMapper waterMapper;

    @RequestMapping("list")
    @EasyExcel(modelClass = WaterExportModel.class)
    public List<Water> list() {
        LambdaQueryWrapper<Water> wrapper = Wrappers.lambdaQuery();
        return waterMapper.selectList(wrapper.last("limit 200"));
    }

    @RequestMapping("page")
    @EasyExcel(modelClass = WaterExportModel.class, resultConverterClass = MybatisPlusPageConverter.class)
    public Page<Water> page(@RequestBody PageReq req) {
        final Page<Water> page = new Page<>(req.getPageIndex(), req.getPageSize(), true);
        return waterMapper.selectPage(page, null);
    }

}
